<?php

// +----------------------------------------------------------------------
// | framework
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zoujingli/framework
// +----------------------------------------------------------------------

namespace app\store\controller;

use library\Controller;
use think\Db;

/**
 * 会员信息管理
 * Class Member
 * @package app\store\controller
 */
class Member extends Controller
{
    /**
     * 绑定数据表
     * @var string
     */
    protected $table = 'StoreMember';

    /**
     * 会员信息管理
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function index()
    {
        $this->title = '会员信息管理';
        $this->_query($this->table)->like('nickname,phone')->equal('vip_level')->dateBetween('create_at')->order('id desc')->page();
    }

    /**
     * 数据列表处理
     * @param array $data
     */
    protected function _page_filter(&$data = [])
    {

        foreach ($data as &$vo) {
            if(isset($vo['nickname'])){
                $vo['nickname'] = urldecode(emoji_decode($vo['nickname']));
            }
            if(isset($vo['use_amount'])){
                $score = $vo['score'] - $vo['used_score'];

                $level_name = Db::table('lite_score_level')->where('start_score', '<=', $score)->where('end_score', '>', $score)->where(['is_deleted' => 0])->value('show_title');
//                var_dump( $level_name, Db::table('lite_score_level')->getLastSql());exit;

                $vo['level_name'] = $level_name;
            }
        }
    }

    public function showRecord()
    {
        $this->title = '积分记录';
        $where = ['is_deleted' => '0', 'open_id' => $this->request->param('open_id')];
        $this->statusTitle = ['1' => '增加', '0' => '减少'];
        $this->_query('lite_member_score_record')->like('name')->where($where)->order('id', 'desc')->page();
    }

}